import { MciSubCard } from '@/components/base';
import { VariableList } from '../VariableList';
import { useGraph } from '@/hooks/useGraph';
import { getAllVariables } from '@/utils/graph';

export const Output = defineComponent({
  setup() {
    const { graph } = useGraph();
    const variables = getAllVariables(graph.value!, 'private') || [];
    const nodeVariables = getAllVariables(graph.value!, 'node') || [];
    variables.push(...nodeVariables);
    const newVariables = variables.reduce((acc, curr) => {
      const found = acc.find((item) => item.varName === curr.varName);
      if (!found) {
        acc.push(curr);
      }
      return acc;
    }, []);
    return () => {
      return (
        <div>
          <MciSubCard title="返回结果">
            <VariableList data={newVariables} />
          </MciSubCard>
        </div>
      );
    };
  }
});
